﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Net;
using System.IO;
using BLL;
using Model;

/// <summary>
///WeiPage 的摘要说明
/// </summary>
public class WeiPage : System.Web.UI.Page
{
    MerchantsBO mbo = new MerchantsBO();
	public WeiPage()
	{
		//
		//TODO: 在此处添加构造函数逻辑
		//
	}

    public string PostRequest(string url)
    {
        HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(url);  //定义请求对象，并设置好请求URL地址
        HttpWebResponse response = (HttpWebResponse)request.GetResponse();    //定义响应对象，request在调用GetResponse方法事执行请求了，而不是在HttpWebRequest.Create的时候执行。
        Stream stream = response.GetResponseStream(); //定义一个流对象，来获取响应流
        StreamReader sr = new StreamReader(stream);  //定义一个流读取对象，读取响应流
        string responseHTML = sr.ReadToEnd();
        return responseHTML;
    }

    public void AlertMessage(string message)
    {
        Page.RegisterStartupScript("AlertMessage", "<script language='javascript'>alert(\"" + message.Replace("'", "′") + "\");</script>");
    }

    /// <summary>
    /// 获取站点根路径
    /// </summary>
    /// <returns></returns>
    protected string GetSitePath()
    {
        string root = Page.Request.ApplicationPath;
        if (root == "/") return root;
        else return root + "/";
    }

    protected  void ReturnMessage(string msg)
    {

        //Exception ex = Server.GetLastError();

        //string root = this.GetSitePath();
        //string css = "<link rel='stylesheet' href='" + root + "Skin/Main.css'/>";
        Response.Clear();
        //Response.Write(css);
        //Response.Write( "<br><br><h3><font color='red'>系统运行发生错误!请联系管理员!</font></h3><br>错误信息:" );
        //Response.Write( "<hr size='1' color='red'><b>" + msg + "</b><hr size='1' color='red'>" );
        //Response.Write(  ex.StackTrace );

        //出错信息提示样式
        string strHtml = "<body  bgcolor='#CCCCCC'><br><br><br><br><br><br>";
        strHtml += "<div align='center'>";
        strHtml += "  <table width='80%' border='1' cellspacing='0' bordercolorlight='000000' bordercolordark='FFFFFF' bgcolor='E0E0E0'>";
        strHtml += "    <tr>";
        strHtml += "      <td><table border='0' bgcolor='#0066CC' cellspacing='0' cellpadding='2'  height='35'  width='100%'>";
        strHtml += "          <tr>";
        strHtml += "            <td align='center'><font color='FFFFFF' size='3'><b>System messages</b></font></td>";
        strHtml += "          </tr>";
        strHtml += "          </table>";
        strHtml += "          <table border='0' width='100%' cellpadding='4'>";
        strHtml += "            <tr>";
        //strHtml += "              <td width='59' align='center' valign='top'><img src='" + root + "images/28.png'/></td>";
        strHtml += "              <td colspan='2' align='center'><font size='2'><b>" + msg + "</b></font></td>";
        strHtml += "            </tr>";
        strHtml += "            <tr>";
        strHtml += "              <td colspan='2' align='center' valign='top'><input type='button' name='ok' class='formButton' value='　Return　' onclick='javascript:history.back()' />";
        strHtml += "              </td>";
        strHtml += "            </tr>";
        strHtml += "        </table></td>";
        strHtml += "    </tr>";
        strHtml += "  </table>";
        strHtml += "</div></body>";

        Response.Write(strHtml);
        Response.End();
    }

    private string _pf;

    public string pf
    {
        get {
            if (Session["ToUserName"] != null)
            {
                Merchants m = mbo.GetModel(Session["ToUserName"].ToString());
                if (m != null)
                    return m.Pf;
                else
                    return "1";
            }
            return "1";
        }
        set { _pf = value; }
    }

    private string _appid;

    public string Appid
    {
        get
        {
            if (Session["ToUserName"] != null)
            {
                Merchants m = mbo.GetModel(Session["ToUserName"].ToString());
                if (m != null)
                    return m.AppId;
                else
                    return "1";
            }
            return "1";
        }
        set { _appid = value; }
    }
    private string _secret;

    public string Secret
    {
        get
        {
            if (Session["ToUserName"] != null)
            {
                Merchants m = mbo.GetModel(Session["ToUserName"].ToString());
                if (m != null)
                    return m.Access_token;
                else
                    return "1";
            }
            return "1";
        }
        set { _secret = value; }
    }
}